(module merge (lib "eopl.ss" "eopl")
  (provide merge)
  
;;1.27
;; merge: List * List -> List
;; usage: (merge loi1 loi2)
;; produces: return a sorted list of all the integers in loi1 and loi2

;; examples:
;; (merge '(1 4) '(1 2 8)) ==> (1 1 2 4 8)
;; (merge '(35 62 81 90 91) '(3 83 85 90)) ==> (3 35 62 81 83 85 90 90 91)

 

(define (merge loi1 loi2)
  (cond
    ((null? loi1) loi2)
    ((null? loi2) loi1)
    ((> (car loi1) (car loi2)) (cons (car loi2) (merge loi1 (cdr loi2))))
    (else (cons (car loi1) (merge loi2 (cdr loi1))));
    )
  )

 

(merge '(1 4) '(1 2 8))
(merge '(35 62 81 90 91) '(3 83 85 90))

)
